package com.qiangua.lixin.qianguakeji;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;


public class MainActivity extends Activity {

    private Button button1;
    private TextView textView1,textView2;


   // private ListView listView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        button1 = (Button) findViewById(R.id.bt1);
        textView1 = (TextView) findViewById(R.id.tv2);
        textView2 = (TextView) findViewById(R.id.tv3);

        textView1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this,Forget.class);
                startActivity(intent);
            }
        });

        textView2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this,ZhuCe.class);
                startActivity(intent);
            }
        });

        //listView = (ListView) findViewById(R.id.listview1);
       /* listView = (ListView) findViewById(R.id.listview2);
        String[]  arr = {"我的设备","消息","账号设置","退出登录"};

        ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_activated_2,arr);

        listView.setAdapter(arrayAdapter);
        */

        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                String number = ((EditText) findViewById(R.id.et1)).getText().toString();
                String password = ((EditText) findViewById(R.id.et2)).getText().toString();

                boolean flag = false;
                String nickName = "";
                for (int i = 0; i < Data.USERS.length; i++) {
                    if (number.equals(Data.USERS[i][0])) {
                        if (password.equals(Data.USERS[i][1])) {
                            nickName = Data.USERS[i][2];
                            flag = true;
                            break;
                        }
                    }
                }
                if (flag) {
                    Intent intent = new Intent(MainActivity.this, SecActivity.class);
                    Bundle bundle = new Bundle();
                    bundle.putString("nickName", nickName);
                    intent.putExtras(bundle);
                    startActivity(intent);
                } else {
                    Toast.makeText(getApplicationContext(), "用户名或密码错误", Toast.LENGTH_LONG).show();
                }
            }
        });





    }

}